﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel;

namespace Enough.Lifecycle.Common
{
    public class AppVersion
    {
        public static string GetVersion(PackageVersion version)
        {
            return    version.Major  + "."
                    + version.Minor  + "."
                    + version.Build  + "."
                    + version.Revision;
        }

        public string CurrentVersion { get; set; }
        public string PreviousVersion { get; set; }

        public bool IsUpdated
        {
            get
            {
                return (CurrentVersion != PreviousVersion);
            }
        }

        public string CurrentVersionWithoutRevision
        {
            get
            {
                string version = CurrentVersion;
                if (version != null)
                {
                    int lastDotIndex = version.LastIndexOf('.');
                    if (lastDotIndex > 1)
                    {
                        version = version.Substring(0, lastDotIndex);
                    }
                }
                return version;
            }
        }
    }
}
